﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using Database;

public partial class admin_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       

    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string username = txt_username.Text;
        string password = txt_password.Text;
        KhachHang kh = new KhachHang();
        kh.Tenkh = username;
        kh.Matkhau = password;
        DataTable table = kh.DangNhapAdmin(kh);
        if (table.Rows.Count > 0)
        {
            string quyen = table.Rows[0]["quyen"].ToString();
            if (quyen == "nhanvien")
            {
                Session["username"] = table.Rows[0]["tenkh"].ToString();
                Session["permission"] = quyen;
                //Session["hoten"] = table.Rows[0]["hoten"].ToString();
                Response.Redirect("TrangChu.aspx");
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "a", "alert('Bạn không phải là Admin!');", true);
                Response.Redirect("../Default.aspx");

            }
        }
        else
        {
            ClientScript.RegisterStartupScript(this.GetType(), "a", "alert('Đăng nhập không thành công!');", true);
        }

        

    }
}

